#param ([string]$Web = $(throw "Path to folder required."))

$Web = "G:\Source\Jakkaj\TechEd\HooIzDat\Web" ;

$PSScriptRoot = Split-Path -Parent -Path (Get-Item -Path $MyInvocation.MyCommand.Path).FullName ;

$SourceFile = Join-Path -Path $Web -ChildPath "Scripts\combined.js" ;
$MinimisedFile = Join-Path -Path $Web -ChildPath "Scripts\combined.min.js" ;
Remove-Item -Path $MinimisedFile -ErrorAction SilentlyContinue ;

Copy-Item -Path $SourceFile -Destination $MinimisedFile ;

$YuiAssemblyPath = Join-Path -Path $PSScriptRoot -ChildPath "Dependencies\Build\Yahoo.Yui.Compressor.dll" ;
[Void][System.Reflection.Assembly]::LoadFrom($YuiAssemblyPath) ;

[string]$JsContent = [string]::join([environment]::newline, (Get-Content -Path $SourceFile -Encoding UTF8)) ;
[Yahoo.Yui.Compressor.JavaScriptCompressor]::Compress($JsContent, $false) |
    Set-Content -Path $MinimisedFile -Encoding UTF8 | Out-Null;

Copy-Item -Path $MinimisedFile -Destination $SourceFile -Force ;
Remove-Item -Path $MinimisedFile -ErrorAction SilentlyContinue ;